package com.nccsjz.back.cardway.service;
import java.sql.SQLException;
import java.util.List;

import com.nccsjz.base.BaseService;
import com.nccsjz.pojo.CardWay;
import com.nccsjz.back.cardway.dao.CardWayDAO;
import com.nccsjz.utils.Pager;
/**
 * 用于处理用卡知识相关的业务逻辑
 * ＠author cpf
 * @version 1.0
 * */
public class CardWayService  extends BaseService{
	//根据主键查看一条用卡知识
	public CardWay getCardWay(long id) throws SQLException{
		CardWay cw=null;
		try{
			openCon();
			cw=new CardWayDAO(con).getCardWay(id);
		}finally{
			closeCon();
		}
		return cw;
	}
	//添加一条用卡知识
	public boolean addCardWay(CardWay cw) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			flag=new CardWayDAO(con).addCardWay(cw);
		}finally{
			closeCon();
		}
		return flag;
	}
	//删除一条用卡知识
	public boolean deleteCardWay(long id) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			flag=new CardWayDAO(con).deleteCardWay(id);
			
		}finally{
			closeCon();
		}
		return flag;
	}
	//分有处理用卡知识
	public Pager getCardWay(int pageSize,int pageNo) throws SQLException{
		Pager pager=null;
		try{
			openCon();
			pager=new CardWayDAO(con).getCardWay(pageSize, pageNo);
		}finally{
			closeCon();
		}
		return pager;
	}
	//修改用卡知识
	public boolean updateCardWay(CardWay cw) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			flag=new CardWayDAO(con).updateCardWay(cw);
		}finally{
			closeCon();
		}
		return flag;
	}
	//批量删除用卡知识
	public boolean deleteBatchCardWay(List<Long> list) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			con.setAutoCommit(false);
			flag=new CardWayDAO(con).deleteBathCardWay(list);
			con.commit();
		}finally{
			closeCon();
		}
		return flag;
	}
	
	//add by changpf
	 /**
	  * 得到前n条用卡知识。
	  * @return
	  */
	public List<CardWay> getTopN(int n) {
		List<CardWay> cw=null;
		try {
			openCon();
			cw=new CardWayDAO(con).getTopN(n);
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				closeCon();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	return cw;
	}
}
